/*
 * OutputHDF5.h
 *
 *  Created on: Aug 9, 2013
 *      Author: paste
 */

#ifndef OUTPUTHDF5_H_
#define OUTPUTHDF5_H_

#include "BaseHDF5.h"
#include <boost/algorithm/string/join.hpp>

// Forward declarations
namespace H5 {
class DataSet;
}

class OutputHDF5 : public virtual BaseHDF5
{
public:

  OutputHDF5(const std::string &filename, const IOMode &ioMode = TRUNCATE,
      const bool &matlab = true);

  virtual ~OutputHDF5() throw ()
  {
  }

  template<typename StoredType>
  void Put(const std::string &path, const StoredType &obj)
  {
    Put(path.c_str(), obj);
  }

  template<typename StoredType>
  void Put(const char *path, const StoredType &obj)
  {
    H5::DataSet ds = Traverse(path);
    Put(ds, obj);
  }

  template<typename StoredType>
  void Put(const std::vector<std::string> &path, const StoredType &obj)
  {
    const std::string pathStr = boost::algorithm::join(path, "/");
    return Put(pathStr.c_str(), obj);
  }

protected:

  bool myMatlab;

  template<typename StoredType>
  void Put(const H5::DataSet &dataSet, const StoredType &obj) const;

private:

  H5::DataSet Traverse(const char *path) const;

};

#endif /* OUTPUTHDF5_H_ */
